<template>
  <div>
    <!-- 面包屑导航条 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/toOneList' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>工艺中心</el-breadcrumb-item>
      <el-breadcrumb-item>工艺管理</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图 -->
    <el-card class="box-card2">
      <!--模糊查询-->
      <el-form :model="searchForm" class="demo-form-inline" >
        <el-row :gutter="20">
          <el-form-item>
            <el-col :span="4">
              <el-input placeholder="请输入订单编号" v-model="searchForm.code"></el-input>
            </el-col>
            <el-button @click="searchList" plain type="info" class="btn"  icon="el-icon-search">搜索</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </el-card>
      <el-card class="box-card">
      <!--工序列表订单-->
      <el-table
        :data="orderList"
        stripe
        style="width: 100%">
        <el-table-column
          type="index"
          width="50">
        </el-table-column>
        <el-table-column
          label="订单编号"
          prop="code">
        </el-table-column>
        <el-table-column
          label="客户"
          prop="customerName">
        </el-table-column>
        <el-table-column
          label="创建时间"
          prop="createDate">
          <template slot-scope="scope">
            {{scope.row.createDate|formatDate}}
          </template>
        </el-table-column>
        <el-table-column
          label="更新时间"
          prop="updateDate">
          <template slot-scope="scope">
            {{scope.row.updateDate|formatDate}}
          </template>
        </el-table-column>
        <el-table-column
          label="状态"
          prop="state">
          <template slot-scope="scope">
            {{scope.row.state | stateFilter}}
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作">
          <template slot-scope="scope">
            <el-popover placement="right" width="200" trigger="click">
              <el-button type="primary"  @click="getorderitem(scope.row)">查看</el-button><!--查看零件列表制作工艺-->
              <el-button slot="reference" type="text">操作</el-button>
            </el-popover>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page.pagenum"
        :page-size="page.pagesize"
        :page-sizes="[5, 10, 20, 40]"
        :total="total"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>

      <el-dialog
        title="BOM明细"
        :visible.sync="itemFormVisible"
        width="30%"> <!--零件列表框 -->
        <el-table
          :data="itemlist"
          stripe
          style="width: 100%">
          <el-table-column
            type="index"
            width="50">
          </el-table-column>
          <el-table-column
            label="订单编号"
            prop="code">
          </el-table-column>
          <el-table-column
            label="图号">
          <template slot-scope="scope">
            <a :href="'/api/orderpic/showPhoto/'+orderForm.code+'/'+scope.row.code" target="_blank">{{scope.row.code}}</a>
            </template>
          </el-table-column>
          <el-table-column
            label="零件名称"
            prop="name">
          </el-table-column>
          <el-table-column
            label="生产数量"
            prop="num">
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作">
            <template slot-scope="scope">
                <el-button type="primary" @click="make(scope.row)">制作</el-button><!--制作工艺-->
            </template>
          </el-table-column>
        </el-table>
        <el-button type="primary" @click="submit(2)">提交</el-button>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
    export default {
        name: "make",
      data() {
        return {
          searchForm:{},
          orderList:[],
          itemFormVisible:false,
          itemlist:[],
          page: {
            pagenum: 0,
            pagesize: 5
          },
          total: 0,
          orderForm:{code:null},
          username:null,
          userId:null,
          codeId:"",
        }
      },
      filters: {
          stateFilter: function (val) {
            if (val == 1) {
              return "已提交";
            }
            if (val == 2) {
              return "已工艺";
            }
            if (val == 3) {
              return "已报价";
            }
            if (val == 4) {
              return "已支付";
            }
            if (val == 5) {
              return "已转合同";
            }
            if (val == 6) {
              return "已关闭";
            }
          },

      },
        methods: {
          submit:function(ck){//提交时查询当前订单是否工序
            this.$http.post("/order/getOrder/"+this.codeId+"/"+ck+"/"+this.username+"/"+this.userId).then((res) => {
              if(res.data.success){
                this.$message.success(res.data.message);
                this.searchList();
                this.itemFormVisible=false;
              }else{
                this.$message.error(res.data.message);
              }
            });
          },
          handleSizeChange: function (val) {
            this.page.pagesize = val;
            this.searchList();
          },
          handleCurrentChange: function (val) {
            this.page.pagenum = val;
            this.searchList();
          },
          searchList: function () {//工序列表工艺员看的，只能展示关键信息。只能显示订单状态为已提交的订单信息
            this.$http.post("/order/makelist/" + this.page.pagenum + "/" + this.page.pagesize+"/"+this.userId, this.searchForm).then((res) => {
              debugger
              this.orderList = res.data.result.list;
              this.total = res.data.result.total;
            });
          },
          updateStatus:function (row,ck) {
            debugger
            let name= this.username;
            let userid=this.userId;
            this.$http.post("order/updateStatus/"+row.id+"/"+ck+"/"+name+"/"+userid).then((res)=>{
              if(res.data.success){
                this.$message.success(res.data.message);
                this.searchList();
              }else{
                this.$message.error(res.data.message);
              }
            })
          },
          getorderitem:function (row) {//查看当前零件
            this.codeId=row.id;
            this.itemFormVisible=true;
            debugger
            this.orderForm.code=row.code;
            this.$http.post("orderitem/itemlist/"+row.id).then((res)=>{
              debugger
              this.itemlist = res.data.result;
            })
          },
          make:function (row) {//跳转制作组件
            let id = row.id;
            debugger
            //跳转路由后查询显示
            this.$router.push('/makeAdd?id=' + id);
          },
        },
        mounted() {
          let user=JSON.parse(sessionStorage.getItem("user")); //=JSON.parse()字符串转json对象 ，JSON。stringify（）对象转字符串
          this.username=user.userName; //当前登录人
          this.userId=user.id; //当前登录人id
          this.searchList();
        }

    }
</script>

<style scoped>
  .box{/*中间的间隔*/
    height: 20px;
    background-color: #eaedf1;
  }
  .box-card2{/*搜索框的样式*/
    height: 80px;
    border-radius: 40px;
  }
  .box-card{/*列表的样式*/
    border-radius: 30px;
  }
  .btn{/*按钮的圆角样式*/
    border-radius: 30px;
  }
</style>
